package com.octopus.core.parser;

import com.octopus.core.Response;
import com.octopus.core.result.Result;
import lombok.Getter;
import lombok.Setter;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

/**
 * 使用JSOUP API解析HTML
 *
 * @author yang_shoulai@hoperun.com
 * @date 2019/02/15
 */
@Setter
@Getter
public class HtmlParser extends TextParser {

  @Override
  public final ParseResult parse(String text, Response response) throws ParseException {
    return this.parse(Jsoup.parse(text), response);
  }

  /**
   * HTML文档解析
   *
   * @param document 文档
   * @param response 响应
   * @return 解析结果
   * @throws ParseException 解析异常
   */
  public ParseResult parse(Document document, Response response) throws ParseException {
    return ParseResult.me().body(Result.me().obj(document));
  }
}
